package test;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class ttt {
    public static List<String> getDatesBetween(String startDateStr, String endDateStr) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate startDate = LocalDate.parse(startDateStr, formatter);
        LocalDate endDate = LocalDate.parse(endDateStr, formatter);
        List<String> dates = new ArrayList<>();
        //这里是判断开始日期是否在结束日期之后或者=结束日期
        while (startDate .isBefore(endDate) || startDate .isEqual(endDate)) {
            String add = startDate .format(formatter);
            dates.add(add);
            startDate = startDate .plusDays(1);
        }
        return dates;
    }

    public static void main(String[] args) {
//        List<String> datesBetween = getDatesBetween("2023-04-04", "2023-04-06");
//        datesBetween.forEach(System.out::println);
        List<String> datesBetween1 = OvertimeDataSynchronization(DateUtil.parse("2023-04-04", DatePattern.NORM_DATE_PATTERN),DateUtil.parse( "2023-04-04", DatePattern.NORM_DATE_PATTERN));
        datesBetween1.forEach(System.out::println);
    }

    public static List<String>  OvertimeDataSynchronization( Date startTime,Date endTime) {
        Calendar start = Calendar.getInstance();
        start.setTime(startTime); // 将开始日期传入Calendar实例中
        start.set(Calendar.HOUR_OF_DAY,0);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime); // 将结束日期传入Calendar实例中
        end.set(Calendar.HOUR_OF_DAY,0);
        List<String> dateList = new ArrayList<String>();

        while (!start.after(end)) { // 判断是否到达结束日期
            dateList.add( DateUtil.format(start.getTime(), DatePattern.NORM_DATE_PATTERN));
            start.add(Calendar.DAY_OF_MONTH, 1); // 日期加一天
        }
     return dateList;
    }

}
